import { DownOutlined } from '@ant-design/icons';
import { Dropdown, Menu, Space,message } from 'antd';
import React ,{ Component }from 'react';
import url from '../../config/url';
import req from '../../http/req'
import './my.css'
const menu = (
    <Menu
        items={[
            {
                label: (
                    <p  onClick={() => { tuichu() }}>
                        退出登录
                    </p>
                ),
                key: '0',
            },
            {
                label: (
                    <a target="_blank" rel="noopener noreferrer" href="https://www.aliyun.com">
                        个人中心
                    </a>
                ),
                key: '1',
            },
            {
                type: 'divider',
            },
            //   {
            //     label: '3rd menu item（disabled）',
            //     key: '3',
            //     disabled: true,
            //   },
        ]}
    />
);
const tuichu = () => {
    if(window.confirm('确实要退出吗?')){
        localStorage.clear();
    window.location.replace("/login")

    }
    
}


class My extends Component {
    state ={
        adminInfo:{}
    }
    render() {
        return (
            <div>
                <Dropdown overlay={menu}>
                    <a onClick={(e) => e.preventDefault()}>
                        <Space style={{flex:1}}>
                            {this.state.adminInfo.username}
                            <DownOutlined />
                        </Space>
                    </a>
                </Dropdown>
            </div>
        );
    }
    componentDidMount() {
        const fn1 = () => req.get(url.CheckJwt)
        const fn2 = () => req.get(url.GetAdminInfo)

        req.all([fn1(), fn2()]).then(
            // res1,res2的顺序与前面的方法的顺序一致
            req.spread((res1, res2) => {
                // console.log(res1.data, res2.data)
                if (res1.data.errNo === 0) {
                    res2.data.errNo === 0 && this.setState({adminInfo:res2.data.accountInfo})
                   
                } else {
                    message.error('请先登录！',1,()=>{
                        this.props.history.replace('/login')
                    })
                    // message.error('请先登录！')
                    
                }
            })
        )
    }
    
}

export default My;


